const $cache = require('../../utils/storage')
const $api = require('../../utils/api').API.mine
Page({

  /**
   * 页面的初始数据
   */
  data: {
    myInfo:null,
    oftenList: [{
        pic: 'https://easeview.oss-cn-shanghai.aliyuncs.com/staticPic/static/ask.png',
        text: '我的问答'
      },
      {
        pic: 'https://easeview.oss-cn-shanghai.aliyuncs.com/staticPic/static/plane.png',
        text: '行业会员'
      },
      {
        pic: 'https://easeview.oss-cn-shanghai.aliyuncs.com/staticPic/static/list.png',
        text: '好友申请'
      },
      {
        pic: 'https://easeview.oss-cn-shanghai.aliyuncs.com/staticPic/static/money.png',
        text: '消费记录'
      },
      {
        pic: 'https://easeview.oss-cn-shanghai.aliyuncs.com/staticPic/static/tuiguang.png',
        text: '我的推广'
      },
      {
        pic: 'https://easeview.oss-cn-shanghai.aliyuncs.com/staticPic/static/customer%20.png',
        text: '平台客服'
      },
      {
        pic: 'https://easeview.oss-cn-shanghai.aliyuncs.com/staticPic/static/game.png',
        text: 'cp盒子'
      },
      {
        pic: 'https://easeview.oss-cn-shanghai.aliyuncs.com/staticPic/static/list.png',
        text: '邀请新人'
      },

    ],
    myList:[],
    school:'',
    QRsrc:''
  },
  handleClose(){
    this.setData({
      QRsrc:''
    })
  },
  downloadPic(){
    wx.downloadFile({
      url: this.data.QRsrc,　　　//需要下载的图片url
      success: function (res) {　　　　　　　　　　　　//成功后的回调函数
        wx.saveImageToPhotosAlbum({　　　　　　　　　//保存到本地
          filePath: res.tempFilePath,
          success(res) {
            wx.showToast({
              title: '保存成功',
              icon: 'success',
              duration: 2000
            })
          },
          fail: function (err) {
            if (err.errMsg === "saveImageToPhotosAlbum:fail auth deny") {
              wx.openSetting({
                success(settingdata) {
                  console.log(settingdata)
                  if (settingdata.authSetting['scope.writePhotosAlbum']) {
                    console.log('获取权限成功，给出再次点击图片保存到相册的提示。')
                  } else {
                    console.log('获取权限失败，给出不给权限就无法正常使用的提示')
                  }
                }
              })
            }
          }
        })
      }
    });
  },
  handleOfen(e){
    let myInfo = $cache._getStorage('userInfo')
    let openId = myInfo.openId
    let index = e.currentTarget.dataset.index
    if(index==7){
      $api.getQRCode({openId}).then(res=>{
        console.log(res)
        this.setData({
          QRsrc:res.data.data
        })
      })
    }else if(index==4){
      wx.navigateTo({
        url: '/pages/my_invetor/my_invetor',
      })
    }else if(index==6){
      wx.navigateTo({
        url: '/pages/cp/cp',
      })
    }
    else{
      this.showHope()
    }
  },
  showHope(){
    wx.showToast({
      title: '敬请期待',
    })
  },
  goSetInfo(){
    wx.redirectTo({
      url: '/pages/my_info_new/my_info-new',
    })
  },
  onLoad(options) {
    let myInfo = $cache._getStorage('userInfo')
    let openId = myInfo.openId
    $api.getMyList({openId}).then(res=>{
      console.log(res,888)
      this.setData({
        myList:res.data.data,
      })
    })
    console.log(myInfo)
    this.setData({
      myInfo
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    let school = $cache._getStorage('schoolName')
    console.log(school)
    this.setData({
      school
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})